package hot;

public class siyiliu {
    public static boolean canPartition(int[] nums) {
        int n=nums.length;
        if(n==1){
            return false;
        }
        int sum=0;
        for(int x:nums){
            sum+=x;
        }
        if(sum%2!=0){
            return false;
        }
        boolean[][] f=new boolean[n+1][sum/2+1];
        for(int i=0;i<n+1;i++){
            f[i][0]=true;
        }
        for(int i=1;i<n+1;i++){
            for(int j=0;j<=sum/2;j++){
                f[i][j]=f[i-1][j];
                if(j>=nums[i-1]){
                    f[i][j]=f[i-1][j]||(f[i-1][j-nums[i-1]]);
                }
            }
        }
        return f[n][sum/2];


    }

    public static void main(String[] args) {
        int[] nums= {1,2,3};
        boolean b = canPartition(nums);
        System.out.println(b);

    }
}
